package logic

import (
	"automated-modeling/models/mysql"
	"context"
	"fmt"

	"automated-modeling/automatedrpc/automatedrpc"
	"automated-modeling/automatedrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductsShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductsShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductsShowLogic {
	return &ProductsShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductsShowLogic) ProductsShow(in *automatedrpc.ProductsShowRequest) (*automatedrpc.ProductsShowResponse, error) {
	// todo: add your logic here and delete this line
	var products mysql.Products
	err := mysql.DB.Debug().Where("id = ?", in.Id).Find(&products).Error
	if err != nil {
		return nil, fmt.Errorf("查看失败")
	}

	return &automatedrpc.ProductsShowResponse{
		Name:   products.Name,
		Cate:   products.Cate,
		Cost:   float32(products.Cost),
		Market: float32(products.Market),
		Image:  products.Image,
		UseId:  int64(products.UserId),
	}, nil
}
